package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.po.SystemConfig;
import com.huilian.iotbox.data.service.SystemConfigService;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author: loong
 * @create: 2021-10-25 14:16
 **/
@RestController
@RequestMapping("/api/systemConfig")
public class SystemConfigController extends BaseController {
    @Resource
    private UserService userService;
    @Resource
    private SystemConfigService systemConfigService;

    @GetMapping("/findSystemConfig")
    public ServerResponse findSystemConfig() {
        return ServerResponse.createBySuccess(systemConfigService.findOneSystemConfigById(1));
    }

    @PostMapping("/update")
    public ServerResponse update(@RequestBody SystemConfig systemConfig, HttpServletRequest request) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        systemConfig.setUserInfo(userInfo);
        return systemConfigService.update(systemConfig);
    }
}
